#! /usr/bin/env python
'''
Auther      : xiaobaiTser
Email       : 807447312@qq.com
createTime  : 2024/10/22 23:30
fileName    : generate_icos.py
'''

from PIL import Image

def generate_ico(name: str = 'paipai.ico', size: int = 256):
    Image.open(name).resize((size, size)).save(name)


def generate_png(name: str = 'paipai.png', size: int = 48, prefix: str = 'round'):
    Image.open(name).resize((size, size)).save(f'{name.split(".")[0]}{prefix}-{size}.{name.split(".")[1]}')


if __name__ == '__main__':
    import os
    # 获取当前目录下icon文件
    icons = os.listdir()
    # 过滤掉不是.ico文件
    icons = list(filter(lambda x: x.endswith('.ico'), icons))
    # 只保留第一个icon文件，其他icon文件删除掉
    for icon in icons[1:]:
        if icon.endswith('.ico'):
            os.remove(icon)
    generate_ico(icons[0])

    # 获取当前目录下png文件，获取第一个，其他png文件删除掉
    pngs = os.listdir()
    pngs = list(filter(lambda x: x.endswith('.png'), pngs))
    for png in pngs[1:]:
        if png.endswith('.png'):
            os.remove(png)

    '''
    需要生成：
    -16.png,-20,-29.png,-32.png,-40.png,-48.png,-58.png,-60.png,-64.png,-72.png,-76.png,-80.png,-87.png,-96.png,
    -120.png,-128.png,-144.png,-152.png,-167.png,-180.png,-192.png,-256.png,-512.png,-640.png,-1024.png,-1280.png,
    -1920.png,
    -adaptive-108.png,-adaptive-162.png,-adaptive-216.png,-adaptive-324.png,-adaptive-432.png,
    -round-48.png,-round-72.png,-round-96.png,-round-144.png,-round-192.png,
    -square-48.png,-square-72.png,-square-96.png,-square-144.png,-square-192.png,
    -square-320.png,-square-480.png,-square-640.png,-square-960.png,-square-1280.png,
    '''
    for item in [
        ('', 16), ('', 20), ('', 29), ('', 32), ('', 40), ('', 48), ('', 58), ('', 60), ('', 64), ('', 72), ('', 76),
        ('', 80), ('', 87), ('', 96), ('', 120), ('', 128), ('', 144), ('', 152), ('', 167), ('', 180), ('', 192),
        ('', 256), ('', 512), ('', 640), ('', 1024), ('', 1280), ('', 1920),
        ('-adaptive', 108), ('-adaptive', 162), ('-adaptive', 216), ('-adaptive', 324), ('-adaptive', 432),
        ('-round', 48), ('-round', 72), ('-round', 96), ('-round', 144), ('-round', 192),
        ('-square', 48), ('-square', 72), ('-square', 96), ('-square', 144), ('-square', 192),
        ('-square', 320), ('-square', 480), ('-square', 640), ('-square', 960), ('-square', 1280),
    ] :
        generate_png(name=pngs[0], prefix=item[0], size=item[1])